#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
using namespace std;
int main()
{
    int m, i, n, a, b, c, d;

    while (cin >> m)
    {
        list<int> l;
        list<int>::iterator j;
        for (i = 0; i < m; i++)
        {
            cin >> n;
            l.push_back(n);
        }
        cin >> a;
        for (i = 0; i < a; i++)
        {
            cin >> b;
            switch (b)
            {
            case 1:
                cin >> c >> d;
                for (j = l.begin(); *j != c && j != l.end(); j++);
                if (j != l.end())
                {
                    l.insert(++j, c);
                }
                break;
            case 2:
                cin >> c;
                for (j = l.begin(); j != l.end(););
                if (*j <= c)
                {
                    l.erase(j++);
                }
                else
                {
                    j++;
                }
                break;
            case 3:
                cin >> c >> d;
                for (j = l.begin(); *j != d && j != l.end(); j++);
                if (j != l.end())
                {
                    l.remove(c);
                    for (j = l.begin(); *j != d && j != l.end(); j++);
                    if (j != l.end())
                    {
                        l.insert(++j, c);
                    }
                }

                break;
            }
        }
        for (j = l.begin(); j != l.end(); j++)
        {
            if (j != l.begin())
                cout << " ";
            cout << *j;
        }
        cout << endl;

    }
    return 0;
}




#include <iostream>
#include <list>
using namespace std;

int main()
{
    int n;
    while (cin >> n) {
        list<int> lst;
        list<int>::iterator j;
        int t, c, a, b;
        for (int i = 0; i < n; i++) {
            cin >> t;
            lst.push_back(t);
        }
        cin >> t;
        for (int i = 0; i < t; i++) {
            cin >> c;
            switch (c) {
            case 1:
                cin >> a >> b;
                for (j = lst.begin(); *j != a && j != lst.end(); j++)
                    ;
                if (j != lst.end())
                    lst.insert(++j, b);
                break;
            case 2:
                cin >> a;
                for (j = lst.begin(); j != lst.end();)
                    if (*j <= a)
                        lst.erase(j++);
                    else
                        j++;
                break;
            case 3:
                cin >> a >> b;
                for (j = lst.begin(); *j != b && j != lst.end(); j++)
                    ;
                if (j != lst.end()) {
                    lst.remove(a);
                    for (j = lst.begin(); *j != b && j != lst.end(); j++)
                        ;
                    if (j != lst.end())
                        lst.insert(++j, a);
                }
                break;
            }
        }
        for (j = lst.begin(); j != lst.end(); j++) {
            if (j != lst.begin())
                cout << " ";
            cout << *j;
        }
        cout << endl;
    }
    return 0;
}



#include <iostream>
#include <string>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int m, n, i, j;
    string ch;
    while (cin >> n >> m)
    {
        queue<int> q[10000];
        for (i = 0; i < m; i++)
        {
            cin >> ch;
            if (ch == "INIT")
            {
                for (j = 0; j < n; i++)
                {
                    while (!q[j].empty())
                        q[j].pop();
                }
            }
            if (ch == "PUSH")
            {
                int id, val;
                cin >> id >> val;
                q[id - 1].push(val);
            }
            if (ch == "POP")
            {
                int id;
                cin >> id;
                if (q[id - 1].empty())
                {
                    cout << "NULL" << endl;
                }
                else
                {
                    cout << q[id - 1].front() << endl;
                }
            }
        }

    }

}



#include <iostream>
#include <list>
#include <set>
using namespace std;
int main()
{

    // multiset<int>::iterator mt=ms.begin();
    int n, m;
    cin >> n;
    while (n) {
        multiset<int> ms;
        for (int i = 0; i < n; i++)
        {
            char ch;
            cin >> ch;
            if (ch == 'B')
            {
                cin >> m;
                ms.insert(m);
            }
            else if (ch == 'G')
            {
                if (!ms.empty())
                {
                    cout << *ms.begin() << endl;
                    ms.erase(ms.begin());
                }
            }
            // mt=ms.begin();

        }
        cin >> n;
    }
    return 0;
}
int main()
{
    multiset<int> ms;
    multiset<int>::iterator mu;
    int n, m;
    while (cin >> n && n)
    {
        multiset<int> ms;
        multiset<int>::iterator mu;
        for (int i = 0; i < n; i++)
        {
            char ch;
            cin >> ch >> m;
            if (ch == 'i')
            {
                ms.insert(m);
            }
            else if (ch == 'd')
            {
                cin >> m;
                mu = ms.find(m);
                ms.erase(mu);
            }
        }
        mu = ms.begin();
        cout << *mu;
        mu++;
        for (; mu != ms.end(); mu++)
        {
            cout << " ";
            cout << *mu;
        }
        cout << endl;
    }
    return 0;
}